package com.konne.nightmare.FastPublicOpinion.utils;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.konne.nightmare.FastPublicOpinion.R;
import com.konne.nightmare.FastPublicOpinion.base.MyApplication;


/***
 * toast
 */
public class ToastUtil {
    private static Toast toast;

    public static void showToast(String content) {
        if (toast == null) {
        toast = Toast.makeText(MyApplication.getContext(),
                null,
                Toast.LENGTH_SHORT);
        } else {
            toast.setText(content);
        }
        toast.setText(content);
        toast.show();
    }
    public static void showSuccessToast(CharSequence msg){
        View view= LayoutInflater.from(ActivityUtils.getTopActivity()).inflate(R.layout.toast_success,null);
        TextView tvmsg=view.findViewById(R.id.tv_msg);
        tvmsg.setText(msg);
       // ToastUtils.make().setGravity(Gravity.CENTER,0,0).setDurationIsLong(false).show(view);
        Toast toast = new Toast(ActivityUtils.getTopActivity());
        toast.setView(view);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER,0,0);
        toast.show();
    }
    public static void showTitleToast(CharSequence title,CharSequence msg){
        View view= LayoutInflater.from(ActivityUtils.getTopActivity()).inflate(R.layout.toast_title_msg,null);
        TextView tvTitle=view.findViewById(R.id.tv_title);
        tvTitle.setText(title);
        TextView tvmsg=view.findViewById(R.id.tv_msg);
        tvmsg.setText(msg);
        // ToastUtils.make().setGravity(Gravity.CENTER,0,0).setDurationIsLong(false).show(view);
        Toast toast = new Toast(ActivityUtils.getTopActivity());
        toast.setView(view);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER,0,0);
        toast.show();
    }
}
